/***************************************************************************//**
 * @file MSc_Matrix6x6.cpp
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2013 Marek M. Cel
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 ******************************************************************************/
#ifndef MSC_MATRIX6X6_CPP
#define MSC_MATRIX6X6_CPP
#endif

////////////////////////////////////////////////////////////////////////////////

#include <utils/MSc_Matrix6x6.h>

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6::MSc_Matrix6x6() :
    MSc_Matrix<6,6>()
{}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6::MSc_Matrix6x6( const MSc_Matrix6x6 &mtrx ) :
    MSc_Matrix<6,6>()
{
    setArray( mtrx.m_items );
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6 MSc_Matrix6x6::getFrom( const double items[] )
{
    MSc_Matrix6x6 result;

    result.setArray( items );

    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6 MSc_Matrix6x6::getTransposed() const
{
    MSc_Matrix6x6 result;

    for ( int r = 0; r < m_rows; r++ )
    {
        for ( int c = 0; c < m_cols; c++ )
        {
            result.m_items[ c*m_cols + r ] = m_items[ r*m_cols + c ];
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6& MSc_Matrix6x6::operator= ( const MSc_Matrix6x6 &mtrx )
{
    setArray( mtrx.m_items );
    
    return (*this);
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6 MSc_Matrix6x6::operator+ ( const MSc_Matrix6x6 &mtrx ) const
{
    MSc_Matrix6x6 result;
    
    for ( int i = 0; i < m_size; i++ )
    {
        result.m_items[ i ] = m_items[ i ] + mtrx.m_items[ i ];
    }
    
    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6 MSc_Matrix6x6::operator- ( const MSc_Matrix6x6 &mtrx ) const
{
    MSc_Matrix6x6 result;
    
    for ( int i = 0; i < m_size; i++ )
    {
        result.m_items[ i ] = m_items[ i ] - mtrx.m_items[ i ];
    }
    
    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6 MSc_Matrix6x6::operator* ( double val ) const
{
    MSc_Matrix6x6 result;
    
    for ( int i = 0; i < m_size; i++ )
    {
        result.m_items[ i ] = m_items[ i ] * val;
    }
    
    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6 MSc_Matrix6x6::operator* ( const MSc_Matrix6x6 &mtrx ) const
{
    MSc_Matrix6x6 result;

    for ( int r = 0; r < m_rows; r++ )
    {
        for ( int c = 0; c < m_cols; c++ )
        {
            result.m_items[ r*m_cols + c ] = 0.0;

            for ( int i = 0; i < m_cols; i++ )
            {
                result.m_items[ r*m_cols + c ] += ( m_items[ r*m_cols + i ] * mtrx.m_items[ i*m_cols + c ] );
            }
        }
    }
    
    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector6 MSc_Matrix6x6::operator* ( const MSc_Vector6 &vect ) const
{
    MSc_Vector6 result;

    for ( int r = 0; r < m_rows; r++ )
    {
        result(r) = 0.0;

        for ( int c = 0; c < m_cols; c++ )
        {
            result(r) += ( m_items[ r*m_cols + c ] * vect(c) );
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6 MSc_Matrix6x6::operator/ ( double val ) const
{
    MSc_Matrix6x6 result;
    
    for ( int i = 0; i < m_size; i++ )
    {
        result.m_items[ i ] = m_items[ i ] / val;
    }
    
    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6& MSc_Matrix6x6::operator+= ( const MSc_Matrix6x6 &mtrx )
{
    for ( int i = 0; i < m_size; i++ )
    {
        m_items[ i ] += mtrx.m_items[ i ];
    }
    
    return (*this);
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6& MSc_Matrix6x6::operator-= ( const MSc_Matrix6x6 &mtrx )
{
    for ( int i = 0; i < m_size; i++ )
    {
        m_items[ i ] -= mtrx.m_items[ i ];
    }
    
    return (*this);
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6& MSc_Matrix6x6::operator*= ( double val )
{
    for ( int i = 0; i < m_size; i++ )
    {
        m_items[ i ] *= val;
    }
    
    return (*this);
}

////////////////////////////////////////////////////////////////////////////////

MSc_Matrix6x6& MSc_Matrix6x6::operator/= ( double val )
{
    for ( int i = 0; i < m_size; i++ )
    {
        m_items[ i ] /= val;
    }
    
    return (*this);
}
